using System.Configuration;
using System.Web.Services;
using System.Xml;
using System;

/*	-----------------------------------------------------------------------	
	Copyright:	umlungu consulting (pty) ltd
	Author:		Alan Benington	
	Started:	2007-04-04	
	Status:		release	
	Version:	2.0.0
	Build:		20070702
	License:	GNU General Public License
	-----------------------------------------------------------------------	*/

/*	-----------------------------------------------------------------------	
	Development Notes:
	==================
	20070404:	This class is a basic web service class to provide an interface
				to the LoggerX classes and functionality.
				In implementation this class serves as a parent, and all or
				select (protected) web methods can  be defined.
				Note that becuase this class has no public methods the 
				protected web methods can be overloaded (maybe they 
				shouldn't have the [WebMethod] attribute? Not sure)
	20070702:	Recompile for .Net 2.0
	-----------------------------------------------------------------------	*/

namespace umlungu.engineX.loggerX {
	/// <summary>
	/// umlungu loggerX web services
	/// </summary>
	[WebService(Namespace="http://www.umlungu.com/engineX/")]
	public class loggerServiceX : x_result {
		#region Private properties
		private x_logalyse logalyse;
		#endregion

		#region Constructors/Destructors
		/// <summary>Constructor</summary>
		public loggerServiceX() : base("LoggerX") {
			logalyse = new x_logalyse();
			logalyse.Path = Server.MapPath("");
		}
		/// <summary>Constructor</summary>
		public loggerServiceX(string ServiceName) : base(ServiceName) {
			logalyse = new x_logalyse();
			logalyse.Path = Server.MapPath("");
		}
		#endregion

		#region Web service methods
		/// <overloads>Gets the log file (log.txt) in an xml format</overloads>
		/// <summary>Gets the current log file</summary>
		/// <returns>Returns an XmlDocument containing  the log enries of the current log</returns>
		[WebMethod] protected XmlDocument _Get() {
			return _Get(false);
		}
		/// <summary>Gets the current log file</summary>
		/// <param name="All">Flag to indicate all files or just current log</param>
		/// <returns>Returns an XmlDocument containing  the log enries of the current log</returns>
		[WebMethod] protected XmlDocument _Get(bool All) {
			return _Get(All, null);
		}
		/// <summary>Gets the current log file</summary>
		/// <param name="All">Flag to indicate all files or just current log</param>
		/// <param name="Prefix">The parameter Prefix to the filter by</param>
		/// <returns>Returns an XmlDocument containing  the log enries of the current log</returns>
		[WebMethod] protected XmlDocument _Get(bool All, string Prefix) {
			try {
				if (All)
					logalyse.Gets(Prefix);
				else
					logalyse.Get();
				_AddOk(logalyse.Status.OuterXml);
			} 
			catch(x_exception e)		{_AddError(e);}
			catch(System.Exception e) 	{_AddError(e);}
			return(Result);
		}
		/// <summary>Gets a specifed log file</summary>
		/// <param name="Date">The date of the log file archive, ie YYYYMMDD</param>
		/// <returns>Returns an XmlDocument containing  the log enries of the current log</returns>
		[WebMethod] protected XmlDocument _Get(int Date) {
			try {
				logalyse.Get(Date);
				_AddOk(logalyse.Status.OuterXml);
			} 
			catch(x_exception e)		{_AddError(e);}
			catch(System.Exception e) 	{_AddError(e);}
			return(Result);
		}

		/// <summary>Gets a specifed log files in a month</summary>
		/// <param name="Year">The year of the log file archives</param>
		/// <param name="Month">The month of the log file archives</param>
		/// <returns>Returns an XmlDocument containing  the log enries of the current log</returns>
		[WebMethod] protected XmlDocument _Get(int Year, int Month) {
			try {
				logalyse.Gets(Year, Month);
				_AddOk(logalyse.Status.OuterXml);
			} 
			catch(x_exception e)		{_AddError(e);}
			catch(System.Exception e) 	{_AddError(e);}
			return(Result);
		}
		/// <summary>Gets filtered entries in the current log file</summary>
		/// <param name="Prefix">The parameter Prefix to the filter by</param>
		/// <returns>Returns an XmlDocument containing  the log enries of the current log</returns>
		[WebMethod] protected XmlDocument _Get(string Prefix) {
			try {
				logalyse.Get(Prefix);
				_AddOk(logalyse.Status.OuterXml);
			} 
			catch(x_exception e)		{_AddError(e);}
			catch(System.Exception e) 	{_AddError(e);}
			return(Result);
		}
		/// <summary>Gets filtered entries in a specifed log file</summary>
		/// <param name="Prefix">The parameter Prefix to the filter by</param>
		/// <param name="Date">The date of the log file archive, ie YYYYMMDD</param>
		/// <returns>Returns an XmlDocument containing  the log enries of the current log</returns>
		[WebMethod] protected XmlDocument _Get(string Prefix, int Date) {
			try {
				logalyse.Get(Prefix, Date);
				_AddOk(logalyse.Status.OuterXml);
			} 
			catch(x_exception e)		{_AddError(e);}
			catch(System.Exception e) 	{_AddError(e);}
			return(Result);
		}
		/// <summary>Gets filtered entries in a log files for a specified month</summary>
		/// <param name="Prefix">The parameter Prefix to the filter by</param>
		/// <param name="Year">The year of the log file archives</param>
		/// <param name="Month">The month of the log file archives</param>
		/// <returns>Returns an XmlDocument containing  the log enries of the current log</returns>
		[WebMethod] protected XmlDocument _Get(string Prefix, int Year, int Month) {
			try {
				logalyse.Gets(Prefix, Year, Month);
				_AddOk(logalyse.Status.OuterXml);
			} 
			catch(x_exception e)		{_AddError(e);}
			catch(System.Exception e) 	{_AddError(e);}
			return(Result);
		}
		#endregion
	}
}
